﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ContadorDeHoras.DTO;
using System.Data.SqlClient;
//using System.Data;

namespace ContadorDeHoras.DAL
{
    public class CommandRetrieveRange:ICommand
    {
        private DateTime diainicio;
        private DateTime diafim;
        public CommandRetrieveRange(DateTime d1, DateTime d2)
        {
            this.diainicio = d1;
            this.diafim = d2;
        }
        public object execute()
        {
            List<DiaDTO> retorno = new List<DiaDTO>();
            Connection conexao = Connection.getConnection();
            SqlCommand c = new SqlCommand("s_sp_by_range", conexao.getConexao());
            c.CommandType = System.Data.CommandType.StoredProcedure;
            c.Parameters.Add(new SqlParameter("@date_start", this.diainicio));
            c.Parameters.Add(new SqlParameter("@date_end", this.diafim));
            SqlDataReader dr = c.ExecuteReader();
            while (dr.Read())
            {
                retorno.Add(new DiaDTO(dr.GetDateTime(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetDateTime(3), dr.GetDateTime(4)));
            }
            conexao.closeConexao();
            return retorno;
        }
    }
}
